home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / PartMaker 4.3 / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-12  |  5.9 KB  |  220 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        File.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This file is where you place various definitions and constant values for
  20. ** DTS.Lib..framework's use.  You will also add some code within the two
  21. ** functions to handle the various document types. */
  22.  
  23.  
  24.  
  25. /*****************************************************************************/
  26.  
  27.  
  28.  
  29. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  30. #include "App.defs.h"        /* Get various application definitions.            */
  31. #include "App.protos.h"        /* Get the prototypes for application.            */
  32.  
  33. #ifndef __ERRORS__
  34. #include <Errors.h>
  35. #endif
  36.  
  37. #ifndef __UTILITIES__
  38. #include "Utilities.h"
  39. #endif
  40.  
  41.  
  42.  
  43. /* In this file, we first set some global values.  This allows the application and
  44. ** DTS.Lib..framework to "know" what is expected for certain default actions. */
  45.  
  46.  
  47. Boolean        gDocCreated;
  48.  
  49. short        gTypeListLen = 1;
  50. SFTypeList    gTypeList = {'PtMd'};
  51.     /* Here we declare the various document types that Wannabe can support.
  52.     ** These definitions are to inform DTS.Lib..framework what documents can be opened. */
  53.  
  54.  
  55.  
  56. /* Some DTS.Lib..framework gTypeList usage notes:
  57. **
  58. ** 1)  Framework uses gTypeList[0] for the default document, if there is one.
  59. ** 2)  NewDocument() is passed a document type.  It searches gTypeList for a match.
  60. **     The index at which the match is found (+1) is used as the string number in the
  61. **     STR# resource rDefaultTitles.  If there aren't enough strings in the STR#
  62. **     resource, then the last string is used.
  63. ** 3)  The gTypeList is used for the StandardFile calls to determine which files
  64. **     can be selected. */
  65.  
  66.  
  67.  
  68. #ifdef powerc
  69. #pragma options align=mac68k
  70. #endif
  71. typedef struct DocFileTypeRec {        /* This is used only to determine the size of the document  */
  72.     FileStateRec    fileState;        /* structure.  We can't just add the three components, as   */
  73.     ConnectRec        connect;        /* it is unclear how much padding any particular compiler   */
  74.     TheDoc            doc;            /* will place on the end of each.                            */
  75. } DocFileTypeRec;                    /* The only place that this should be used is in this file. */
  76. #ifdef powerc
  77. #pragma options align=reset
  78. #endif
  79.  
  80.  
  81.  
  82. /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
  83. ** application.  The first 16 are reserved for the framework.  Our application-specific
  84. ** objects start at 16. */
  85.  
  86. TreeObjProcPtr    gTreeObjMethods[kNumTreeObjs] = {nil,
  87. /* 1  */                                         TRootObj,
  88. /* 2  */                                         TUndoObj,
  89. /* 3  */                                         TUndoTaskObj,
  90. /* 4  */                                         TUndoPartObj,
  91. /* 5  */                                         nil,
  92. /* 6  */                                         nil,
  93. /* 7  */                                         nil,
  94. /* 8  */                                         nil,
  95. /* 9  */                                         nil,
  96. /* 10 */                                         nil,
  97. /* 11 */                                         nil,
  98. /* 12 */                                         nil,
  99. /* 13 */                                         nil,
  100. /* 14 */                                         nil,
  101. /* 15 */                                         nil};
  102. /* 16 Start of app-specific procs. */
  103.  
  104.  
  105.  
  106. /* The framework needs to know the minimum object sizes.  This table is used by the
  107. ** framework to make sure that the object is created at least minimally. */
  108.  
  109. long            gMinTreeObjSize[kNumTreeObjs] = {0,
  110. /* 1  */                                         sizeof(RootObj),
  111. /* 2  */                                         sizeof(UndoObj),
  112. /* 3  */                                         sizeof(UndoTaskObj),
  113. /* 4  */                                         sizeof(UndoPartObj),
  114. /* 5  */                                         0,
  115. /* 6  */                                         0,
  116. /* 7  */                                         0,
  117. /* 8  */                                         0,
  118. /* 9  */                                         0,
  119. /* 10 */                                         0,
  120. /* 11 */                                         0,
  121. /* 12 */                                         0,
  122. /* 13 */                                         0,
  123. /* 14 */                                         0,
  124. /* 15 */                                         0};
  125. /* 16 Start of app-specific sizes. */
  126.  
  127.  
  128.  
  129. /*****************************************************************************/
  130. /*****************************************************************************/
  131.  
  132. #ifdef applec
  133. #pragma segment File
  134. #endif
  135.  
  136. /*****************************************************************************/
  137. /*****************************************************************************/
  138.  
  139.  
  140.  
  141. /* •• Called by DTS.Lib..framework. •• */
  142.  
  143. /* Do any additional document initialization here.  All fields not specifically set
  144. ** are already initialized to 0. */
  145.  
  146. OSErr    InitDocument(FileRecHndl frHndl)
  147. {
  148.     OSErr    err;
  149.     OSType    sft;
  150.  
  151.     err = noErr;
  152.  
  153.     gDocCreated = true;
  154.  
  155.     sft = (*frHndl)->fileState.sfType;
  156.     switch (sft) {
  157.         case 'PtMd':
  158.         case 'fold':
  159.         case 'rsrc':
  160.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  161.             if (!err) {
  162.                 /* Any additional document initialization could go here. */
  163.             }
  164.             break;
  165. #ifndef powerc
  166.         case '6hlp':
  167.             err = HelpInitDocument(frHndl);
  168.             break;
  169. #endif
  170. #if VH_VERSION
  171.         case kViewHierFileType:
  172.             return(VHInitDocument(frHndl));
  173.             break;
  174. #endif
  175.         default:
  176.             if (sft == 'fold') return(userCanceledErr);
  177.             if (sft == 'rsrc') return(userCanceledErr);
  178.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  179.             if (!err) {
  180.                 (*frHndl)->fileState.readDocumentProc  = nil;
  181.                 (*frHndl)->fileState.writeDocumentProc = nil;
  182.             }
  183.             break;
  184.     }
  185.  
  186.     return(err);
  187. }
  188.  
  189.  
  190.  
  191. /*****************************************************************************/
  192.  
  193.  
  194.  
  195. /* •• Called by DTS.Lib..framework. •• */
  196.  
  197. /* Return the initial size of the primary document handle, based on the OSType. */
  198.  
  199. long    InitDocumentSize(OSType sftype)
  200. {
  201.     switch (sftype) {
  202.         case 'PtMd':
  203.         case 'fold':
  204.         case 'rsrc':
  205.             return(sizeof(DocFileTypeRec));
  206.             break;
  207. #if VH_VERSION
  208.         case kViewHierFileType:
  209.             return(VHFileTypeSize());
  210.             break;
  211. #endif
  212.         default:
  213.             return(sizeof(DocFileTypeRec));
  214.             break;
  215.     }
  216. }
  217.  
  218.  
  219.  
  220.